<template>
  <div class="Home">
    <el-container>
      <el-header>
        <div>
          <img src="../assets/heima.png" alt />
          <span>电商后台管理系统</span>
        </div>
        <el-button type="info" @click="logout">logou</el-button>
      </el-header>
      <el-container>
        <el-aside :width="isWidth">
          <div class="tog" @click="toggleCollapse">|||</div>
          <el-menu
            class="el-menu-vertical-demo"
            background-color="#333744"
            text-color="#fff"
            active-text-color="#409BFF"
            :unique-opened="true"
            :collapse="isCollapse"
            :collapse-transition="false"
            router
            :default-active="navStatus"
          >
            <el-submenu :index="meun.id +''" v-for="meun in MenuList" :key="meun.id">
              <template slot="title">
                <i :class="iconsObj[meun.id]"></i>
                <span class="csapn">{{meun.authName}}</span>
              </template>

              <el-menu-item
                :index="'/'+submenu.path"
                v-for="submenu in meun.children"
                :key="submenu.id"
                @click="saveNav('/'+submenu.path)"
              >
                <template slot="title">
                  <i class="el-icon-menu"></i>
                  <span>{{submenu.authName}}</span>
                </template>
              </el-menu-item>
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>
<script>
export default {
  name: 'Home',
  data() {
    return {
      MenuList: [],
      iconsObj: {
        '125': 'el-icon-user-solid',
        '103': 'el-icon-eleme',
        '101': 'el-icon-delete-solid',
        '102': 'el-icon-s-goods',
        '145': 'el-icon-document'
      },
      isCollapse: false,
      isWidth: '200px',
      navStatus: ''
    }
  },
  created() {
    this.getMenuList(), this.getNavStatus()
  },
  methods: {
    logout() {
      window.sessionStorage.clear()
      this.$router.push({ name: 'Login' })
    },
    getMenuList() {
      this.$axios.get('menus').then(result => {
        // console.log(result.data)
        this.MenuList = result.data.data
      })
    },
    toggleCollapse() {
      this.isCollapse = !this.isCollapse
      if (this.isCollapse == false) {
        return (this.isWidth = '200px')
      }
      return (this.isWidth = '64px')
    },
    saveNav(nav) {
      window.sessionStorage.setItem('navPath', nav)
      this.navStatus = nav
    },
    getNavStatus() {
      this.navStatus = window.sessionStorage.getItem('navPath')
      //   console.log(this.navStatus, 1)
    }
  }
}
</script>
<style scoped>
.Home {
  height: 100%;
}
.Home > section {
  height: 100%;
}
.el-header {
  background-color: #373d41;
  display: flex;
  justify-content: space-between;
  padding-left: 0;
  align-items: center;
  color: #fff;
  font-size: 20px;
}
.el-header > div {
  display: flex;
  align-items: center;
}
.el-header > div > span {
  padding-left: 15px;
}
.el-aside {
  background-color: #333744;
}
.el-main {
  background-color: #eaedf1;
}
.el-menu {
  border-right: none !important;
}
.csapn {
  margin-left: 5px;
}
.tog {
  background-color: #4a5064;
  font-size: 10px;
  line-height: 24px;
  color: #fff;
  text-align: center;
  letter-spacing: 0.2em;
  cursor: pointer;
}
</style>